home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '91 / Hacks '91 / Makin' Copies / Source / pStr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-16  |  2.5 KB  |  132 lines  |  [TEXT/KAHL]

  1. /*pascal format string functions Written by and property of: Eric J. Hayes*/
  2. /*non-profit use of this library must be accompanyed by a credit to myself.*/
  3. /*sale of all or any part of this library or it's headers prohibited without*/
  4. /*written permission of myself*/
  5. /* ®1987-1991 Eric J. Hayes*/
  6.  
  7. #pragma mark  HEADERS
  8.         #include "pStr.h"
  9.  
  10.  
  11. #pragma mark  PROTOS
  12.         void pStrCpy(char*,char*);
  13.         void pStrCat(char*,char*);
  14.         void pRightJust(char*,short);
  15.         short pStrCmp(char*,char*,short,short,short);
  16.  
  17.  
  18. void pStrCpy(outStr,inStr)
  19.  char*    inStr;
  20.  char*    outStr;
  21.     {
  22.     short    xx;
  23.     short in  = inStr[0]  & 0x00FF;
  24.     short    out = outStr[0] & 0x00FF;
  25.     
  26.     for (xx=0; xx<=in; xx++)
  27.         outStr[xx] = inStr[xx];
  28.     }
  29.  
  30. void pStrCat(outStr,inStr)
  31.  char*    inStr;
  32.  char*    outStr;
  33.     {
  34.     short    xx;
  35.     short in  = inStr[0]  & 0x00FF;
  36.     short    out = outStr[0] & 0x00FF;
  37.  
  38.     if ( (in + out) > 255 )  /*make sure there is enough room*/
  39.         {
  40.         in = 255 - out;
  41.         }
  42.         
  43.     for (xx=1; xx<=in; xx++)
  44.         outStr[out+xx] = inStr[xx];
  45.     
  46.     outStr[0] = out+in;
  47.     }
  48.  
  49. void pRightJust(theStr,places)
  50.  char*    theStr;
  51.  short            places;
  52.     {
  53.     Str255    tempStr;
  54.     short            theOffset;
  55.     short            xx;
  56.     
  57.     if ( theStr[0] < places )
  58.         {
  59.         pStrCpy((char*)tempStr,(char*)theStr);
  60.         theOffset = places - theStr[0];
  61.         theStr[0] = places;
  62.         for(xx=1    ;xx<=places            ;theStr[xx++] = ' ');    
  63.         for(xx=1    ;xx<=theStr[0]    ;theStr[xx+theOffset] = tempStr[xx++]);
  64.         }
  65.     }
  66.     
  67. short pStrCmp(ned,hay,mode,hayoffset,casetype)
  68.  char*        ned;
  69.  char*        hay;
  70.  short        mode;
  71.  short        hayoffset;
  72.  short        casetype;
  73.     {
  74.     char    tempchar;
  75.     short    xx,yy,err,loops;
  76.     Str255    temp_ned,temp_hay;
  77.     
  78.     pStrCpy((char*)temp_ned,ned);
  79.     pStrCpy((char*)temp_hay,hay);
  80.  
  81.     if ( casetype == 1 )
  82.         {
  83.         UprString (temp_ned,FALSE);
  84.         UprString (temp_hay,FALSE);
  85.         }
  86.         
  87.     switch(mode)
  88.         {
  89.         case str_equals:        
  90.             if ( hayoffset == 0 )
  91.                 xx = 0;
  92.             else
  93.                 xx = 1;
  94.             for (;xx<=temp_ned[0];xx++)
  95.                 if ( temp_ned[xx] != temp_hay[xx+hayoffset] )
  96.                     return(BAD);
  97.             break;
  98.         case str_contains:
  99.             if (temp_ned[0] == temp_hay[0])
  100.                 {
  101.                 err = pStrCmp(ned,hay,str_equals,0,casetype);
  102.                 return(err);
  103.                 }
  104.             else
  105.                 {
  106.                 loops = temp_hay[0] - temp_ned[0];
  107.                 for(xx=0;xx<=loops;xx++)
  108.                     {
  109.                     err = pStrCmp(ned,hay,str_equals,xx,casetype);
  110.                     if ( err == GOOD )
  111.                         return(GOOD);
  112.                     }
  113.                 return(BAD);
  114.                 }
  115.             break;
  116.         case str_starts:
  117.             for (xx=1;xx<=temp_ned[0];xx++)
  118.                 if ( temp_ned[xx] != temp_hay[xx] )
  119.                     return(BAD);
  120.             break;
  121.         case str_ends:
  122.             yy = temp_hay[0] - temp_ned[0];
  123.             for (xx=1;xx<=temp_ned[0];xx++)
  124.                 if ( temp_ned[xx] != temp_hay[xx+yy] )
  125.                     return(BAD);
  126.             break;
  127.         }
  128.         
  129.     return(GOOD);
  130.     }
  131.  
  132.